<?php
/**
 * Created by PhpStorm.
 * User: tom_xia
 * Date: 2018/3/28
 * Time: 15:21
 * 配置加载类
 */

namespace app\cls\tom;
class Config
{
    private static $configPath  = APP_ROOT."/config/";
    private static $config;

    /**
     * @param $configFileName string 配置文件名称
     * @param string $reName string 重定向
     * @return
     */
    public  static function load($configFileName,$reName="")
    {
        if(empty($reName)){
            $reName = strval($configFileName);
        }else{
            $reName = strval($reName);
        }
        if(isset(static::$config[$reName])){
            return static::$config[$reName] ;
        }
        $fullPath = static::$configPath.$configFileName.".php";
        if(file_exists($fullPath)){
            static::$config[$reName] = include $fullPath;
            return static::$config[$reName];
        }else{
//            throw new \Exception("config file not exist !");
            return [];
        }
    }

    /**
     * @param $key string 配置文件的名称
     * @param $itemName string 配置元素的名称
     * @return bool|null
     */
    public static function item($key,$itemName = "")
    {
        if(empty($itemName)){
            return empty(static::$config[$key]);
        }
        if(isset(static::$config[$key][$itemName])){
            return static::$config[$key][$itemName];
        }else{
            return NULL;
        }
    }
}